use rquickjs::{module::ModuleDef, Ctx, Function};


pub struct CalcModule;

impl CalcModule {
    const R: f32 = 8.314;
}

impl ModuleDef for CalcModule {
    fn declare<'js>(decl: &rquickjs::module::Declarations<'js>) -> rquickjs::Result<()> {
        decl.declare("r")?;
        decl.declare("mole")?;
        Ok(())
    }

    fn evaluate<'js>(ctx: &Ctx<'js>, exports: &rquickjs::module::Exports<'js>) -> rquickjs::Result<()> {
        exports.export("r", Self::R)?;
        exports.export("mole", Function::new(ctx.clone(), |p:f32, v: f32, t:f32| p*v/Self::R/t)?.with_name("mole"))?;
        Ok(())
    }
}